package homework;

//八、用程序判断2018年2月14日是星期几。

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Date;

public class Demo4 {
    public static void main(String[] args) throws ParseException {
        //创建一个字符串
        String now="2018年2月14日";
        //模板
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
        //String->date
        Date date = sdf.parse(now);
        //创建系统的当前日历对象
        Calendar c =Calendar.getInstance();
        //通过日历设置，把之前date装进去
        c.setTime(date);
        System.out.println(c);
        int week = c.get(Calendar.DAY_OF_WEEK);
        System.out.println(getWeek(week));


    }
    private static void method() {
        //获取系统的当前日历对象
        Calendar calendar = Calendar.getInstance();
        //设置当前的年
        calendar.set(Calendar.YEAR,2018);
        //month从0开始至11，代表1-12。设置月
        calendar.set(Calendar.MONTH,1);
        //设置当前的日
        calendar.set(Calendar.DAY_OF_MONTH,14);
        //获取得到当前是周几
        int weekDay = calendar.get(Calendar.DAY_OF_WEEK);
        //调用方法
        String weekday = getWeek(weekDay);
        //输出
        System.out.println(weekday);
    }

    public static String getWeek(int week){
        String[] strings = {" ","星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
        return strings[week];
    } 
}
